home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Bus / A / AciusTN8-92.cpt / AciusTN8-92 / GraphicalButtonsƒ / ButtonPkg-US / ButtonPackage.p < prev    next >
Text File  |  1992-10-10  |  18KB  |  708 lines

  1. {$D+}
  2. {$R+}
  3. {écrit par François Marchal, © ACI 1991}
  4. {Version 1.3}
  5.  
  6. {Historique des versions : 
  7.   0.5 Première version sous formes de routines indépendantes
  8.       implémentée dans 4D Desk
  9.   1.0 Intégration dans un package externe
  10.           Implémentation de : Activer/Inactiver
  11.                                   Valeurs par défaut
  12.                                   Display Methode
  13.           Parution dans la note technique NT23
  14.   1.1 Optimisation des IdleEvent
  15.           Implémentation dans la démo QuickTime
  16.   1.2 Gestion de la validité des paramètres
  17.           Signature des Handles
  18.   1.3 Gestion du disabled pour les boutons radios
  19.   1.4 Suppression du double appel par ENTRYPOINT
  20.   1.5 Gestion des boutons en offscreen
  21.   1.6 Correction d'un gros bug à l'Update Event:
  22.           La ressource du bloc est maintenant lockée
  23.         avant le DrawButton. Le problème était aléatoire
  24.         sans les offscreens, et fréquent depuis.
  25. }
  26.  
  27. Unit Button_Pack4D;
  28.  
  29. Interface
  30.  
  31. Uses Memory, QuickDraw, OSIntf, Toolintf, PackIntf, Events, QDOffscreen, Access0;
  32. Type
  33.         ParamBloc = record
  34.                         DefaultstdPICTResUp,
  35.                         DefaultstdPICTResDown,
  36.                         DefaultstdPICTDisabled,
  37.                         DefaultrbPICTResUp,
  38.                         DefaultrbPICTResDown,
  39.                         DefaultrbPICTDisabled,
  40.                         DefaultFont,
  41.                         DefaultSize,
  42.                         DefaultStyle,
  43.                         DefaultUpXOffset,
  44.                         DefaultUpYOffset,
  45.                         DefaultDownXOffset,
  46.                         DefaultDownYOffset,
  47.                         DefaultJumpedChar,
  48.                         DefaultDisplayMethod : Integer;
  49.                     end;
  50.         ParamBlocPtr = ^ParamBloc;
  51.         ParamBlocHandle = ^ParamBlocPtr;
  52.                         
  53.         Bloc =         record
  54.                         Signature : longint;
  55.                         PICTResUp,
  56.                         PICTResDown,
  57.                         PICTDisabled,
  58.                         FontButton,
  59.                         SizeButton,
  60.                         StyleButton,
  61.                         UpXOffset,
  62.                         UpYOffset,
  63.                         DownXOffset,
  64.                         DownYOffset,
  65.                         DisplayMethod : Integer;
  66.                         TitleButton    :    Str255;
  67.                         clicked  : Integer;
  68.                         enabled    : Boolean;
  69.                         AreaRect : Rect;
  70.                     end;
  71.         BlocPtr = ^Bloc;
  72.         BlocHandle = ^BlocPtr;
  73.  
  74. Const
  75.         stdPicUpLocalRes           = 1;
  76.         stdPicDownLocalRes        = 2;
  77.         rbPicUpLocalRes           = 3;
  78.         rbPicDownLocalRes            = 4;
  79.         down                            = 1;
  80.         up                                = 0;
  81.         inactif                        = -1;
  82.         RadioButton                    = 1;
  83.         StandardButton                = 2;
  84.         PictScale                    = 1;
  85.         AreaScale                    = 2;
  86.         ValidSignature                = $464D4250; {'FMBP'}
  87.  
  88.  
  89. Procedure thePackage(ProcNum:Longint; PtrList:PackageVariablesPtr; Var Data:ParamBlocHandle; Var FuncPtr:PackRetParam);
  90. Procedure DrawButton(var TheBloc : BlocHandle; var TheRect : Rect; state : Integer);
  91. procedure DrawStructure( TheParamBloc : ParamBlocHandle; TheName : Str255; TheType : Integer; TheRect : Rect);
  92. Function isValid(TheBloc : BlocHandle) : boolean;
  93. Procedure Button_ExternalArea(    var    TheEvent : EventRecord;
  94.                                             var    TheRect     : Rect;
  95.                                             var    TheName     : Str255;
  96.                                             var    TheBloc     : BlocHandle;
  97.                                             var    TheParamBloc : ParamBlocHandle;
  98.                                                     TheType  : Integer);
  99.  
  100. Implementation
  101.  
  102. Procedure thePackage(ProcNum:Longint; PtrList:PackageVariablesPtr; Var Data:ParamBlocHandle; Var FuncPtr:PackRetParam);
  103. Var
  104.     TheInt : Integer;
  105.     TheBloc : BlocHandle;
  106.  
  107. Begin
  108.     Case ProcNum Of
  109.  
  110.         1    : { ButtonExternalArea }
  111.         if PtrList^[1].EV^.what <> NullEvent then
  112.             if Data<>Nil then
  113.             begin
  114.                 HLock(handle(Data));
  115.                 Button_ExternalArea(PtrList^[1].EV^,
  116.                                           PtrList^[2].RE^,
  117.                                           PtrList^[3].S^,
  118.                                           BlocHandle(PtrList^[4].HH^),
  119.                                           Data,
  120.                                           StandardButton);
  121.                 HUnLock(handle(Data));
  122.             end;{if Data<>Nil}
  123.  
  124.             
  125.         2    :    {RadioButtonExternalArea}
  126.         if PtrList^[1].EV^.what <> NullEvent then
  127.             if Data<>Nil then
  128.             begin
  129.                 HLock(handle(Data));    
  130.                 Button_ExternalArea(PtrList^[1].EV^,
  131.                                           PtrList^[2].RE^,
  132.                                           PtrList^[3].S^,
  133.                                           BlocHandle(PtrList^[4].HH^),
  134.                                           Data,
  135.                                           RadioButton);
  136.                 HUnLock(handle(Data));
  137.             end;    {if Data<>Nil}
  138.     
  139.         (-1)    :
  140.         Begin    {Init Package}
  141.             Data := ParamBlocHandle(NewHandle(SizeOf(ParamBloc)));
  142.             if Data <> Nil then
  143.             begin
  144.                 Hlock(Handle(Data));
  145.                 With Data^^ do
  146.                 begin
  147.                     DefaultstdPICTResUp:=GetResNum('4BNX','PICT',stdPicUpLocalRes);
  148.                     DefaultstdPICTResDown:=GetResNum('4BNX','PICT',stdPicDownLocalRes);
  149.                     DefaultrbPICTResUp:=GetResNum('4BNX','PICT',rbPicUpLocalRes);
  150.                     DefaultrbPICTResDown:=GetResNum('4BNX','PICT',rbPicDownLocalRes);
  151.                     DefaultstdPICTDisabled:=(-1);
  152.                     DefaultrbPICTDisabled:=(-1);
  153.                     DefaultJumpedChar:=1;
  154.                     DefaultFont:=0;
  155.                     DefaultSize:=12;
  156.                     DefaultStyle:=0;
  157.                     DefaultUpXOffset:=(-1);
  158.                     DefaultUpYOffset:=(-1);
  159.                     DefaultDownXOffset:=0;
  160.                     DefaultDownYOffset:=0;
  161.                     DefaultDisplayMethod:= PictScale;
  162.                 end;    {With Data^^}
  163.                 HUnLock(Handle(Data));
  164.             end;    {if Data<>Nil}
  165.         end; {InitPackage}
  166.  
  167.         
  168.         (-2)    : {DeInit Package}
  169.         if Data<>Nil then DisposHandle(handle(Data));
  170.  
  171.     
  172.         3    :    {GetButton}
  173.         Begin
  174.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  175.             if isValid(TheBloc) then
  176.                 With TheBloc^^ do
  177.                 begin
  178.                     FuncPtr.I:=clicked;
  179.                     if clicked=down then    clicked:=up;
  180.                 end;
  181.         end; {GetButton}
  182.  
  183.  
  184.         4    :    {ReadButton}
  185.         Begin
  186.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  187.             if isValid(TheBloc) then
  188.                     FuncPtr.I:=TheBloc^^.clicked;
  189.         end; {ReadButton}
  190.         
  191.  
  192.         5    :    {SetRadioButton}
  193.         Begin
  194.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  195.             if isValid(TheBloc) then
  196.                 TheInt:=PtrList^[2].I^;
  197.                 if (TheInt=1) or (TheInt=0) then
  198.                     if TheBloc^^.clicked<>TheInt then
  199.                     begin
  200.                         TheBloc^^.clicked:=TheInt;
  201.                         InValRect(TheBloc^^.AreaRect);
  202.                     end;
  203.         end; {Case 5}
  204.  
  205.  
  206.         6    :    {DisableButton}
  207.         Begin
  208.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  209.             if isValid(TheBloc) then
  210.                 if TheBloc^^.enabled then
  211.                 begin
  212.                     TheBloc^^.enabled:=False;
  213.                     InValRect(TheBloc^^.AreaRect);
  214.                 end;
  215.         end; {DisableButton}
  216.  
  217.  
  218.         7    :    {EnableButton}
  219.         Begin
  220.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  221.             if isValid(TheBloc) then
  222.                 if not(TheBloc^^.enabled) then
  223.                 begin
  224.                     TheBloc^^.enabled:=True;
  225.                     InValRect(TheBloc^^.AreaRect);
  226.                 end;
  227.         end; {EnableButton}
  228.  
  229.  
  230.         8    :    {SetPICTButton}
  231.         Begin
  232.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  233.             if isValid(TheBloc) then
  234.                 With TheBloc^^ do
  235.                 begin
  236.                     if PtrList^[2].I^ >=0         then PICTResUp     := PtrList^[2].I^;
  237.                     if PtrList^[3].I^ >=0         then PICTResDown     := PtrList^[3].I^;
  238.                     if PtrList^[4].I^ >=(-1)     then PICTDisabled    := PtrList^[4].I^;
  239.                     InValRect(TheBloc^^.AreaRect);
  240.                 end;    {With TheBloc^^ do}
  241.         end; {SetPICTButton}
  242.     
  243.  
  244.         9    :    {SetButtonTitle}
  245.         Begin
  246.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  247.             if isValid(TheBloc) then
  248.                 With TheBloc^^ do
  249.                 begin
  250.                     TitleButton:=PtrList^[2].S^;
  251.                     if PtrList^[3].I^ >=0 then FontButton :=PtrList^[3].I^;
  252.                     if PtrList^[4].I^ >=0 then SizeButton :=PtrList^[4].I^;
  253.                     if PtrList^[5].I^ >=0 then StyleButton:=PtrList^[5].I^;
  254.                     InValRect(TheBloc^^.AreaRect);
  255.                 end; {With TheBloc^^}
  256.         end; {SetButtonTitle}
  257.  
  258.  
  259.         10    :    {SetButtonOffset}
  260.         Begin
  261.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  262.             if isValid(TheBloc) then
  263.                 With TheBloc^^ do
  264.                 begin
  265.                     UpXOffset := PtrList^[2].I^;
  266.                     UpXOffset := PtrList^[3].I^;
  267.                     UpXOffset := PtrList^[4].I^;
  268.                     UpXOffset := PtrList^[5].I^;
  269.                     InValRect(TheBloc^^.AreaRect);
  270.                 end;
  271.         End;    {SetButtonOffset}
  272.  
  273.  
  274.         11 :    {SetDisplayMethod}
  275.         begin
  276.             TheBloc:=BlocHandle(PtrList^[1].HH^);
  277.             if isValid(TheBloc) then
  278.                 With TheBloc^^ do
  279.                 begin
  280.                     case PtrList^[2].I^ of
  281.                         PictScale :
  282.                             DisplayMethod:=PictScale;
  283.                         AreaScale :
  284.                             DisplayMethod:=AreaScale;
  285.                     end; {Case PtrList^[2].I^}
  286.                     InValRect(TheBloc^^.AreaRect);
  287.                 end;
  288.         end;    
  289.  
  290.         12    :    {SetDefaultPICT}
  291.             if Data <> Nil then
  292.             begin
  293.                 HLock(Handle(Data));
  294.                 With Data^^ do
  295.                 begin
  296.                     if PtrList^[1].I^>0 then
  297.                         DefaultstdPICTResUp:=PtrList^[1].I^
  298.                     else
  299.                         if PtrList^[1].I^=0 then
  300.                             DefaultstdPICTResUp:=GetResNum('4BNX','PICT',stdPicUpLocalRes);
  301.                     
  302.                     if PtrList^[2].I^>0 then
  303.                         DefaultstdPICTResDown:=PtrList^[2].I^
  304.                     else
  305.                         if PtrList^[2].I^=0 then
  306.                             DefaultstdPICTResDown:=GetResNum('4BNX','PICT',stdPicDownLocalRes);
  307.  
  308.                     if PtrList^[3].I^>(-2) then DefaultstdPICTDisabled:=PtrList^[3].I^;
  309.  
  310.                     if PtrList^[4].I^>0 then
  311.                         DefaultrbPICTResUp:=PtrList^[4].I^
  312.                     else
  313.                         if PtrList^[4].I^=0 then
  314.                             DefaultrbPICTResUp:=GetResNum('4BNX','PICT',rbPicUpLocalRes);
  315.  
  316.                     if PtrList^[5].I^>0 then
  317.                         DefaultrbPICTResDown:=PtrList^[5].I^
  318.                     else
  319.                         if PtrList^[5].I^=0 then
  320.                             DefaultrbPICTResDown:=GetResNum('4BNX','PICT',rbPicDownLocalRes);
  321.  
  322.                     if PtrList^[6].I^>(-2) then DefaultrbPICTDisabled:=PtrList^[6].I^;
  323.                     
  324.                 end;    {With Data^^}
  325.                 HUnLock(Handle(Data));
  326.             end;
  327.  
  328.         13    :    {SetDefaultStyle}
  329.             if Data <> Nil then
  330.                 With Data^^ do
  331.                 begin
  332.                     DefaultJumpedChar:=PtrList^[1].I^;
  333.                     if PtrList^[2].I^>=0 then
  334.                         DefaultFont:=PtrList^[2].I^;
  335.                     if PtrList^[3].I^>=0 then
  336.                         DefaultSize:=PtrList^[3].I^;
  337.                     if PtrList^[4].I^>=0 then
  338.                         DefaultStyle:=PtrList^[4].I^;
  339.                 end;    {With Data^^}
  340.  
  341.  
  342.         14    :    {SetDefaultOffset}
  343.             if Data <> Nil then
  344.                 With Data^^ do
  345.                 begin
  346.                     DefaultUpXOffset:=PtrList^[1].I^;
  347.                     DefaultUpYOffset:=PtrList^[2].I^;
  348.                     DefaultDownXOffset:=PtrList^[3].I^;
  349.                     DefaultDownYOffset:=PtrList^[4].I^;
  350.                 end;    {With Data^^}
  351.  
  352.         15 : {SetDefaultDisplayMethod}
  353.             if Data <> Nil then
  354.             begin
  355.                 case PtrList^[1].I^ of
  356.                     PictScale :
  357.                         Data^^.DefaultDisplayMethod:=PictScale;
  358.                     AreaScale :
  359.                         Data^^.DefaultDisplayMethod:=AreaScale;
  360.                 end;
  361.             end;
  362.             
  363.         16 : {Convert FontName to FontNum}
  364.             begin
  365.                 GetFNum(PtrList^[1].S^,TheInt);
  366.                 FuncPtr.L:=Longint(TheInt);
  367.             end;
  368.  
  369.     end;    {case ProcNum}
  370. end;    {procedure ENTRYPOINT}
  371.  
  372. Procedure DrawButton(var TheBloc : BlocHandle; var TheRect : Rect; state : Integer);
  373. var
  374.     ThePict         : PicHandle;
  375.     PictRect        : Rect;
  376.     TextPoint     : Point;
  377.     FntInfo        : FontInfo;
  378.     FntHeight    : Integer;
  379.     Trame            : Pattern;
  380.     TheMaxPixelSize         : integer;
  381.     TheMaxRect                 : Rect;
  382.     TheMaxDevice             : GDHandle;
  383.     TheMaxCTable             : CTabHandle;
  384.     ThePictureGWorld,
  385.     currPort                 : CGrafPtr;
  386.     currdev                    : GDHandle;
  387.     err                         : QDErr;
  388.     isLock                     : boolean;
  389. begin
  390.     With TheBloc^^ do
  391.     begin
  392.         if enabled or (PICTDisabled<>0) then
  393.         begin
  394.             if not(enabled) and (PICTDisabled<>(-1)) then
  395.                 ThePict:=GetPicture(PICTDisabled)
  396.             else
  397.                 if state = up then
  398.                     ThePict:=GetPicture(PICTResUp)
  399.                 else
  400.                     ThePict:=GetPicture(PICTResDown);
  401.  
  402.             if ThePict<>Nil then
  403.             begin    
  404.                 Case DisplayMethod of
  405.                     PictScale :
  406.                     begin
  407.                         PictRect:=ThePict^^.picFrame;
  408.                         offsetRect(PictRect,-PictRect.left,-PictRect.top);
  409.                         offsetRect(PictRect,TheRect.left,TheRect.top);
  410.                     end;
  411.                     AreaScale :
  412.                         PictRect:=TheRect;
  413.                 end; {Case DisplayMethod}
  414.  
  415.                 GetGWorld(currport,currDev);
  416.             
  417.                 TheMaxRect:=GetGrayRgn^^.rgnBBox;
  418.                 TheMaxDevice:=GetMaxDevice(TheMaxRect);
  419.                 TheMaxPixelSize:=TheMaxDevice^^.gdPMap^^.pixelsize;
  420.                 TheMaxCTable:=TheMaxDevice^^.gdPMap^^.pmTable;
  421.     
  422.                 Err:=NewGWorld(ThePictureGWorld,TheMaxPixelSize,PictRect,TheMaxCTable,Nil,[]);
  423.     
  424.                 if Err=NoErr then
  425.                 begin
  426.                     SetGWorld(ThePictureGWorld,Nil);
  427.                     IsLock:=LockPixels(ThePictureGWorld^.portPixmap);
  428.                     EraseRect(PictRect);
  429.                 end
  430.                 else
  431.                     SetGWorld(currport,currDev);                    
  432.                 
  433.                 DrawPicture(ThePict, PictRect);
  434.  
  435.                 if length(TitleButton) > 0 then
  436.                 begin
  437.                     TextFont(FontButton);
  438.                     TextSize(SizeButton);
  439.                     TextFace(style(byte(StyleButton)));
  440.                     TextMode(SrcOr);
  441.                     GetFontInfo(FntInfo);
  442.                     FntHeight:=FntInfo.Ascent+FntInfo.Descent;
  443.                     TextPoint.h:=    PictRect.Left
  444.                             +(((PictRect.Right-PictRect.Left)
  445.                             -Stringwidth(TitleButton))div 2);
  446.                     TextPoint.v:=    PictRect.Bottom
  447.                             -(((PictRect.Bottom-PictRect.top)-FntHeight) div 2)
  448.                             -fntinfo.Descent;
  449.                     if state = up then
  450.                         MoveTo(TextPoint.h+UpXOffset,
  451.                                  TextPoint.v+UpYOffset)
  452.                     else
  453.                         MoveTo(TextPoint.h+DownXOffset,
  454.                                  TextPoint.v+DownYOffset);
  455.                     DrawString(TitleButton);
  456.                 end;
  457.                 if not(enabled) and (PICTDisabled=(-1)) then
  458.                 begin
  459.                     GetIndPattern(Trame,SysPatListID,4);
  460.                     PenMode(patBic);
  461.                     PenPat(Trame);
  462.                     PaintRect(PictRect);
  463.                 end;
  464.                 
  465.  
  466.                 if Err=NoErr then
  467.                 begin
  468.                     SetGWorld(currport,currDev);
  469.                     UnlockPixels(ThePictureGWorld^.portPixmap);
  470.                     Copybits(GrafPtr(ThePictureGWorld)^.portBits,GrafPtr(currport)^.portbits, PictRect, PictRect, srcCopy, Nil);
  471.                     DisposeGWorld(ThePictureGWorld);
  472.                 end;
  473.  
  474.             end;
  475.         end;
  476.     end;
  477. end;
  478.  
  479.  
  480. procedure DrawStructure( TheParamBloc : ParamBlocHandle; TheName : Str255; TheType : Integer; TheRect : Rect);
  481. var
  482.     ThePict : PicHandle;
  483.     PictRect    : Rect;
  484. begin
  485.     With TheParamBloc^^ do
  486.     begin
  487.         case TheType of
  488.             StandardButton :
  489.                 ThePict := GetPicture(DefaultstdPICTResUp);
  490.             RadioButton :
  491.                 ThePict := GetPicture(DefaultrbPICTResUp);
  492.         end;
  493.         if ThePict<>Nil then
  494.         begin
  495.             PenNormal;
  496.             Case DefaultDisplayMethod of
  497.                 PictScale :
  498.                 begin
  499.                     PictRect:=ThePict^^.picFrame;
  500.                     offsetRect(PictRect,-PictRect.left,-PictRect.top);
  501.                     offsetRect(PictRect,TheRect.left,TheRect.top);
  502.                 end;
  503.                 AreaScale :
  504.                     PictRect:=TheRect;
  505.             end;
  506.             DrawPicture(ThePict,PictRect);
  507.             FrameRect(TheRect);
  508.             MoveTo(TheRect.left+5,TheRect.top+10);
  509.             TextFont(1);
  510.             TextSize(9);
  511.             TextFace([]);
  512.             TextMode(SrcOr);
  513.             DrawString(TheName);
  514.         end;
  515.     end;
  516. end;
  517.  
  518. Function isValid(TheBloc : BlocHandle) : boolean;
  519. var
  520.     i : integer;
  521.     v : boolean;
  522. begin
  523.     v:=false;
  524.     if TheBloc<>Nil then
  525.         if GetHandleSize(handle(TheBloc))>0 then
  526.             if TheBloc^^.Signature=ValidSignature then
  527.                 v:=True;
  528.     if not(v) then i:=Alert(GetResNum('4BNX','ALRT',0),Nil);
  529.     isValid:=v;
  530. end;
  531.  
  532.  
  533. Procedure Button_ExternalArea(    var    TheEvent : EventRecord;
  534.                                             var    TheRect     : Rect;
  535.                                             var    TheName     : Str255;
  536.                                             var    TheBloc     : BlocHandle;
  537.                                             var    TheParamBloc : ParamBlocHandle;
  538.                                                     TheType  : Integer);
  539. var
  540.     ThePoint    : Point;
  541.     DejaInRect,
  542.     IsInRect    : Boolean;
  543.     
  544. begin
  545.     If TheParamBloc <> Nil then
  546.     case TheEvent.What of
  547.  
  548.         MouseDown: 
  549.         begin
  550.             if isValid(TheBloc) then
  551.             begin
  552.                 Hlock(handle(TheBloc));
  553.                 With TheBloc^^ do
  554.                 begin
  555.                     if enabled then
  556.                         Case TheType of
  557.                             StandardButton :
  558.                             begin
  559.                                 DrawButton(TheBloc,TheRect,down);
  560.                                 Clicked:=Down;
  561.                                 While Stilldown do
  562.                                 begin 
  563.                                     GetMouse(ThePoint);
  564.                                     if PtInRect(ThePoint,TheRect) then
  565.                                     begin
  566.                                         if Clicked=Up then 
  567.                                         begin
  568.                                             DrawButton(TheBloc,TheRect,down);
  569.                                             Clicked:=Down;
  570.                                         end;
  571.                                     end
  572.                                     else
  573.                                     begin
  574.                                         if Clicked=Down then
  575.                                         begin
  576.                                             DrawButton(TheBloc,TheRect,up);
  577.                                             Clicked:=Up;
  578.                                         end;
  579.                                     end;
  580.                                 end; {Stilldown}                                        
  581.                                 if clicked=Down then DrawButton(TheBloc,TheRect,up);
  582.                             end; {Case StandardButton}
  583.  
  584.  
  585.                             RadioButton :
  586.                             begin
  587.                                 if Clicked=Down then
  588.                                     Clicked:=Up
  589.                                 else
  590.                                     Clicked:=Down;
  591.                                     
  592.                                 DrawButton(TheBloc,TheRect,clicked);
  593.                                 DejaInRect:=True;
  594.  
  595.                                 While Stilldown do
  596.                                 begin 
  597.                                     GetMouse(ThePoint);
  598.                                     IsInRect:=ptinrect(ThePoint,TheRect);
  599.                                     if IsInRect<>DejaInRect then
  600.                                     begin
  601.                                         if Clicked=Down then
  602.                                             Clicked:=Up
  603.                                         else
  604.                                             Clicked:=Down;
  605.                                         DrawButton(TheBloc,TheRect,clicked);
  606.                                         DejaInRect:=IsInRect;
  607.                                     end;
  608.                                 end; {While Stilldown}
  609.                             end; {RadioButton}
  610.                         end {Case TheType}
  611.                     else
  612.                         Clicked:=inactif;
  613.                     end;    {With TheBloc^^}
  614.                 HUnlock(handle(TheBloc));
  615.             end;{if TheBloc<>Nil}
  616.         end; {Case MouseDown}
  617.     
  618.         StructEvent:
  619.         begin
  620.             DrawStructure(TheParamBloc,TheName,TheType,TheRect);
  621.             TheEvent.Message:=ZoneIsCustomized;
  622.         end;
  623.  
  624.  
  625.         UpdateEvt:
  626.             if isValid(TheBloc) then
  627.             begin
  628.                 Hlock(handle(TheBloc));
  629.                 case TheType of
  630.                     StandardButton :
  631.                         DrawButton(TheBloc,TheRect,up);
  632.                     RadioButton :
  633.                         DrawButton(TheBloc,TheRect,TheBloc^^.clicked);
  634.                 end;
  635.                 HUnlock(handle(TheBloc));
  636.             end;
  637.                 
  638.         InitEvent:
  639.         begin
  640.             TheBloc:=BlocHandle(NewHandle(sizeof(Bloc)));
  641.             if TheBloc <> Nil    then
  642.             begin
  643.                 Hlock(handle(TheBloc));
  644.                 with TheBloc^^, TheParamBloc^^ do
  645.                 begin
  646.                     Signature:=ValidSignature;
  647.                     TitleButton:='';
  648.                     case TheType of
  649.                         StandardButton :
  650.                         begin
  651.                             PICTResUp:=DefaultstdPICTResUp;
  652.                             PICTResDown:=DefaultstdPICTResDown;
  653.                             PICTDisabled:=DefaultstdPICTDisabled;
  654.                             if  (DefaultJumpedChar>=0)
  655.                               & (DefaultJumpedChar<length(TheName)) then
  656.                                 TitleButton:=Copy(TheName,
  657.                                                         1+DefaultJumpedChar,
  658.                                                         Length(TheName)-DefaultJumpedChar);
  659.                             end;    {StandardButton}
  660.                         RadioButton :
  661.                         begin
  662.                             PICTResUp:=DefaultrbPICTResUp;
  663.                             PICTResDown:=DefaultrbPICTResDown;
  664.                             PICTDisabled:=DefaultrbPICTDisabled;
  665.                         end;    {RadioButton}
  666.                     end;    {Case TheType}
  667.                     clicked:=up;
  668.                     enabled:=True;
  669.                     FontButton:=DefaultFont;
  670.                     SizeButton:=DefaultSize;
  671.                     StyleButton:=DefaultStyle;
  672.                     UpXOffset:=DefaultUpXOffset;
  673.                     UpYOffset:=DefaultUpYOffset;
  674.                     DownXOffset:=DefaultDownXOffset;
  675.                     DownYOffset:=DefaultDownYOffset;
  676.                     DisplayMethod:=DefaultDisplayMethod;
  677.                     AreaRect:=TheRect;
  678.                 end; {with TheBloc^^, TheParamBloc^^}
  679.                 HUnlock(handle(TheBloc));
  680.             end; {if TheBloc<>Nil}
  681.         end; {InitEvent}
  682.  
  683.         DeInitEvent:
  684.             if isValid(TheBloc) then DisposHandle(handle(TheBloc));
  685.  
  686.     end; {Case TheEvent.What}
  687. end; {Button_ExternalArea}
  688.         
  689. end.
  690.  
  691.  
  692.  
  693. { Script de compilation pour MPW 3.2
  694.  
  695. Pascal ButtonPackage.p
  696.  
  697. Link -p  ButtonPackage.p.o ∂
  698.              interface.o ∂
  699.              PasLib.o ∂
  700.              Access0.o ∂
  701.      -m    THEPACKAGE ∂
  702.     -sg Main=PASLIB ∂
  703.     -rt 4DPX=26000 ∂
  704.     -sn 'Main'='Button Package' ∂
  705.     -t    'PEXT' ∂
  706.     -c    '4DMX' ∂
  707.     -o    ButtonPackage.Ext
  708. }